package com.kzy.demoadmin.web.mapper;

import com.kzy.demoadmin.web.entity.User;
import com.kzy.demoadmin.web.entity.UserPageQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 返回用户列表
     * @return
     */
    List<User> searchBy(UserPageQuery query);

    /**
     * 新增用户
     * @param u
     */

    void insertUser(User u);

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from sys_user where username = #{username} limit 1")
    User findByUsername(@Param("username") String username);//@param注解是为了告诉MyBatis，这个参数的值，要传入到SQL中，#{username}

    /**
     * 根据用户名和密码查询用户
     * @param username
     * @param password
     * @return
     */
    @Select("select * from sys_user where username = #{username} and password = #{password} limit 1")
    User findByNameAndPassword(@Param("username")String username, @Param("password")String password);

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("select * from sys_user where id = #{id} limit 1")
    User findById(@Param("id") Integer id);

    /**
     * 修改用户
     * @param user
     */
    void edit(User user);

    /**
     * 删除用户
     * @param id
     * @return
     */
    @Delete("delete from sys_user where id = #{id}")
    int deleteById(Integer id);
}
